/*
 * @Description: 提示框确认按钮
 * @Author: liyuhao
 * @Date: 2022-01-28 21:00:39
 * @LastEditors: liyuhao
 * @LastEditTime: 2022-06-01 17:25:01
 */
import React from 'react'
import {Popconfirm} from 'antd'
import SpinButton from '../SpinButton'
import {PopconfirmProps} from 'antd/lib/popconfirm'
import {SpinButtonProps} from '@/components/SpinButton'

export interface PopconfirmButtonProps {
    title: PopconfirmProps['title']
    disabled?: PopconfirmProps['disabled']
    loading?: SpinButtonProps['loading']
    onConfirm?: PopconfirmProps['onConfirm']
    onCancel?: PopconfirmProps['onCancel']
    danger?: boolean,
    popconfirmProps?: Omit<PopconfirmProps, 'title' | 'disabled' | 'onConfirm' | 'onCancel'>
    buttonProps?: Omit<SpinButtonProps, 'loading' | 'disabled'>
    children: React.ReactNode
}

const PopconfirmButton: React.FC<PopconfirmButtonProps> = props => {
    const {title, disabled, loading, onConfirm, onCancel, popconfirmProps, buttonProps, children, danger} = props

    return (
        <Popconfirm
            title={title}
            disabled={disabled}
            onConfirm={onConfirm}
            onCancel={onCancel}
            {...popconfirmProps}
        >
            <div data-tigger="body" style={{display: "inline-block"}}>
                <SpinButton
                    type="link"
                    danger={danger}
                    style={{padding: 0}}
                    loading={loading}
                    disabled={disabled}
                    {...buttonProps}
                >{children}</SpinButton>
            </div>
        </Popconfirm>
    )
}

export default PopconfirmButton
